package com.wlc.exceldownload;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

public class ExcelDownload {

    public static void download() throws ClientProtocolException, IOException {




        //1,导包
        //2,得到HttpClient对象
        HttpClient client = new DefaultHttpClient();

        //3,设置请求方式
        HttpGet get = new HttpGet("http://47.111.24.200:8084/tmp/excel/wanglichao.xls");

        //4,执行请求, 获取响应信息
        HttpResponse response = client.execute(get);

        if(response.getStatusLine().getStatusCode() == 200)
        {
            //得到实体
            HttpEntity entity = response.getEntity();

            byte[] data = EntityUtils.toByteArray(entity);

            //存入磁盘
            FileOutputStream fos = new FileOutputStream(new File("E:\\test\\a.xls"));
            fos.write(data);
            fos.close();

            System.out.println("sharecertificate.xls文件下载成功!!!!");
        }
    }

    public static void main(String[] args) {
        try {
            download();
        } catch (IOException e) {
            System.out.println("发生错误，错误为"+e.getMessage());
        }
    }
}
